package com.ufo.leet;

import java.util.Arrays;

public class No27RemoveElement {
    public static void main(String[] args){
        No27RemoveElement a = new No27RemoveElement();
        int[] numbs = new int[]{1,2,0,3,2,5,6,73,3};
        int len2 = a.removeElement(numbs, 2);
        System.out.println(len2);
        int[] numbs2=new int[len2];
        System.arraycopy(numbs,0,numbs2,0,len2);
        System.out.println(Arrays.toString(numbs2));
    }
    public int removeElement(int[] nums, int val) {
        int slowIdx=0;
        for(int idx = 0; idx < nums.length; idx++) {
            if(nums[idx] != val) {
                nums[slowIdx++] = nums[idx];
                /*
                * if(slowIdx<idx)nums[slowIdx]=nums[idx];
                * slowIdx++;
                * */
            }
            //else nothing; and then idx faster than slowIdx by 1;
        }
        return slowIdx;
    }
}
